<?php

class test extends Thread {

    public $name = '';
    public $runing = false;

    public function __construct($name) {

        $this->name = $name;
        $this->runing = true;
    }

    public function run() {



        printf("name: %s %s\n", $this->name, 1);

        sleep(1);
        $username = 'admin';
        $password = 'mac@@123456';
        $loginUrl = 'http://123.30.50.155/anphatcrm/index.php';
        $ch = curl_init();

//Set the URL to work with
        curl_setopt($ch, CURLOPT_URL, $loginUrl);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)');
// ENABLE HTTP POST
        curl_setopt($ch, CURLOPT_POST, 1);

//Set the post parameters
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'user_name=' . $username . '&user_password=' . $password . '&module=Users&return_action=Login&return_module=Users&action=Authenticate');

//Handle cookies for the login
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//execute the request (the login)
        $store = curl_exec($ch);
        curl_setopt($ch, CURLOPT_URL, 'http://123.30.50.155/anphatcrm/index.php?module=Products&action=index&parenttab=Products');
        $content = curl_exec($ch);
        curl_close($ch);
        printf('%s %s \n ', 'ok', 1);
    }

}

for ($i = 0; $i < 80; $i++) {
    $pool[] = new test($i);
}
foreach ($pool as $t) {
    $t->start();
}